<?php

class MovieInsertView extends View {

	protected $directorsList;
	protected $actorsList;
	protected $categoryList;
	protected $error;

	function __construct() {
	
	}
	
	function setError($e) {
		$this->error = $e;
	}
	
	function getError() {
		return $this->error;
	}
	
	function display() {
	
		if (isset($this->error)) {
			echo $this->error;
		}
		echo '<form method="POST" action="index.php?page=store_manager&view=insertMovie">';
		echo '<table border="0">';
		echo '<tr><td>Title:</td><td><input type="text" name="title" value="'.$_POST['title'].'" /></td></tr>';
		echo '<tr><td>Year:</td><td><input type="text" name="year" value="'.$_POST['year'].'" /></td></tr>';
		echo '<tr><td>Director:</td><td>'; $this->generateDirectorDropdown(); echo '</td></tr>';
		echo '<tr><td>Category:</td><td>'; $this->generateCategoryDropdown(); echo '</td></tr>';
		echo '<tr><td>Rating:</td><td><select name="rating"><option value="G">G</option><option value="PG">PG</option><option value="PG-13">PG-13</option><option value="R">R</option><option value="NC-17">NC-17</option></select></td></tr>';
		echo '<tr><td>Number of copies:</td><td><input type="text" name="noCopies" value="'.$_POST['noCopies'].'" /></td></tr>';
		echo '<tr><td>Price:</td><td><input type="text" name="price" value="'.$_POST['price'].'" /></td></tr>';
		echo '<input type="hidden" name="action" value="save" />';
		echo '<tr><td></td><td><input type="submit" value="submit" class="btn btn-default" /></td></tr>';
		
		echo '</table>';
		echo '</form>';
		echo '<br />';
		echo '<hr />';
		echo '<br />';
		echo '<p>Before submitting a movie, you may choose actors too.</p>';
		echo '<form method="POST" action="index.php?page=store_manager&view=insertMovie">';
		echo '<table border="0">';
		echo '<tr><td>Actor name:</td><td>';$this->generateActorDropdown();echo'</td></tr>';
		echo '<tr><td>isMajor:</td><td><select name="isMajor"><option value="0">No</option><option value="1">Yes</option></select></td></tr>';
		echo '<input type="hidden" name="action" value="actor_save" />';
		echo '<tr><td></td><td><input type="submit" value="submit" class="btn btn-default" /></td></tr>';
		
		echo '</table>';
		echo '</form>';
	}
	
	function getDirectorsList() {
		return $this->directorsList;
	}
	
	function setDirectorsList($d) {
		$this->directorsList = $d;
	}
	
	function getActorsList() {
		return $this->actorsList;
	}
	
	function setActorsList($d) {
		$this->actorsList = $d;
	}
	
	function getCategoryList() {
		return $this->categoryList;
	}
	
	function setCategoryList($d) {
		$this->categoryList = $d;
	}
	
	function generateDirectorDropdown() {
		echo '<select name="directorID">';
		foreach ($this->directorsList as $dir) {
			echo '<option value="'.$dir->getId().'">'.$dir->getFirstName().' '.$dir->getLastName().'</option>';
		}
		echo '</select>';
	}
	
	function generateActorDropdown() {
		echo '<select name="actorID">';
		foreach ($this->actorsList as $dir) {
			echo '<option value="'.$dir->getId().'">'.$dir->getFirstName().' '.$dir->getLastName().'</option>';
		}
		echo '</select>';
	}
	
	function generateCategoryDropdown() {
		echo '<select name="catId">';
		foreach ($this->categoryList as $dir) {
			echo '<option value="'.$dir->getId().'">'.$dir->getCategory().'</option>';
		}
		echo '</select>';
	}

}

?>